#include "../engine/CommonHeads.h"
#include "../engine/Log.h"
#include "../src/PWGameClass.h"

CGameClass*		g_GameClass = NULL;
char*			g_GameTitle = "Personal World";
unsigned int	g_WndWidth = 1024;
unsigned int	g_WndHeight = 768;
bool			g_Fullscreen = false;



bool InitGameClass(CD3D9Engine* engine)
{
	g_GameClass = new CPWGameClass(engine);

	return (g_GameClass != NULL);
}



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdline, int cmdShow)
{
	LogInit();

	bool Status = false;
	CD3D9Engine* engine = new CD3D9Engine();

	if(engine->CreateEngineApp(g_GameTitle, g_WndWidth, g_WndHeight, g_Fullscreen))
	{
		Status = InitGameClass(engine);

		if(Status &&
			g_GameClass->InitGameStates())
		{
			while(engine->IsRunning() &&
					g_GameClass->IsRunning())
			{
				g_GameClass->BeginFrame();
				if(engine->Idle())
				{
					g_GameClass->UpdateInput();
					g_GameClass->UpdateLogic();
					g_GameClass->UpdateGraphics();
				}
				g_GameClass->EndFrame();
			}

			g_GameClass->CleanupGame();
		}
	}

	SAFE_DELETE(engine);
	SAFE_DELETE(g_GameClass);

	LogClose();
	return 0;
}